/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : main.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-01-15 init v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
********************************************************************************
*/
#include "led_factory.h"

#define MAIN_LOGI(fmt, args...) printf("%d Main I: " fmt, __LINE__, ##args)
#define MAIN_LOGD(fmt, args...) printf("%d Main D: " fmt, __LINE__, ##args)
#define MAIN_LOGW(fmt, args...) printf("%d Main W: " fmt, __LINE__, ##args)
#define MAIN_LOGE(fmt, args...) printf("%d Main E: " fmt, __LINE__, ##args)
#define MAIN_LOG(fmt, args...)  printf(fmt, ##args)

int main(int argc, char *argv[])
{
    CLedFactory *theLedFactory = CLedFactory::GetInstance();
    if (!theLedFactory) {
        MAIN_LOGE("Get Led Factory failed!\n");
        return -1;
    }

    // ------------------- UnShare Led Test ------------------------
    MAIN_LOG("-> UnShare led test 1st!\n");
    CLed *thePowerLed1 = theLedFactory->GetLed(LED_UNSHARED);
    if (thePowerLed1) {
        thePowerLed1->Start();
    } else {
        MAIN_LOGE("Get Power Led failed!\n");
    }

    thePowerLed1->Relase();

    MAIN_LOG("\n-> UnShare led test 2nd!\n");
    CLed *thePowerLed2 = theLedFactory->GetLed(LED_UNSHARED);
    if (thePowerLed2) {
        thePowerLed2->Start();
    } else {
        MAIN_LOGE("Get Power Led failed!\n");
    }
    // -------------------      Test End    ------------------------

    // -------------------  Share Led Test  ------------------------
    MAIN_LOG("\n-> Share led test 1st!\n");
    CLed *theLed1 = theLedFactory->GetLed(LED_SHARED, LED_MODE_HORSE);
    if (theLed1) {
        theLed1->Start();
    } else {
        MAIN_LOGE("Get Led failed!\n");
    }

    MAIN_LOG("\n-> Share led test 2nd!\n");
    CLed *theLed2 = theLedFactory->GetLed(LED_SHARED, LED_MODE_BREATH);
    if (theLed2) {
        theLed2->Start();
    } else {
        MAIN_LOGE("Get Led failed!\n");
    }

    // Share Led 仅有两个，若不释放占用的Led。Led3就拿不到资源
    MAIN_LOG("\n-> Share led test 3rd!\n");
    CLed *theLed3 = theLedFactory->GetLed(LED_SHARED, LED_MODE_BREATH);
    if (theLed3) {
        theLed3->Start();
    } else {
        MAIN_LOGE("Get Led failed!\n");
    }
    // -------------------      Test End    ------------------------

    return 0;
}
